#include<iostream>
using namespace std;
const int N = 5e4 + 10;
int arr[N];
int s[N];
int n, k;
int cnt[N] = { 1 };
int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
		arr[i] %= 2;
		s[i] = s[i - 1] + arr[i];
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		cnt[s[i]]++;
		ans += cnt[s[i] - k];
	}
	cout << ans << endl;
	return 0;
}